<?php

class Registrasi extends Controller {

	function Registrasi(){
		parent::Controller();	
	}
	function _setConstant(){
		$data['js1'] = 'jquery-1.4.2.js';
		$data['js2'] = 'jquery.form.js';
		$data['js3'] = "jquery.validate.pack.js";
		$data['aboutLink'] = base_url().'main/about';
		$data['contactLink'] = base_url().'main/contact';
		$data['helpLink'] = base_url().'main/help';
		return $data;
	}
	function index($uid=NULL,$regkey=NULL){
		$this->load->model('User');
		$data = $this->_setConstant();
		$data ['pageTitle'] = 'Selamat Datang di I-See, Silakan Lakukan Registrasi';
		$data['isError'] = FALSE;
		if($this->session->userdata('isLogin')){
				redirect('/dashboard/');
		}else{
			if($uid==NULL||$regkey==NULL){
				$data['isError'] = TRUE;
				$data['error'] = "Anda tidak diizinkan memasuki halaman ini sebelum melakukan proses pendaftaran";
				//Link home;	
			}else{			
				if($this->User->isActive($uid)){
					$data['isError'] = TRUE;
					$data['error'] = "Anda sudah melakukan registrasi silakan ke halaman login";
					//Link login	
				}elseif($this->User->isCocok($uid,$regkey)){
					$data['uid'] = $uid;
					$this->load->model('UserMahasiswa');
					$userMhs = json_decode($this->UserMahasiswa->getNama($uid));
					$data['namaLengkap'] = $userMhs->nama;
					$data['nim'] = $userMhs->nim;
				}elseif($this->User->isRegister($uid)){
					$data['isError'] = TRUE;
					$data['error'] = "Anda memasukkan link konfirmasi yang salah harap cek email anda";
				}else{
					$data['isError'] = TRUE;
					$data['error'] = "Anda tidak diizinkan memasuki halaman ini sebelum melakukan proses pendaftaran";
				}
				
			}
			$this->load->view('registrasi',$data);
		}
	}
}